package com.wgly.question.service;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.wgly.question.bean.Topic;
import com.wgly.question.bean.TopicExample;
import com.wgly.question.bean.TopicExample.Criteria;
import com.wgly.question.dao.TopicMapper;
@Service
public class TopicService {
	private static TopicMapper topicMapper;
	@Autowired
	public void setTopicMapper(TopicMapper topicMapper) {
		TopicService.topicMapper = topicMapper;
	}
	public static void writesTopic(Topic topic) {
		// TODO Auto-generated method stub  
		// wgly.question.
		topicMapper.insertSelective(topic);
	}
	public static  boolean checkProblem(String problem) {
		// TODO Auto-generated method stub
		TopicExample example = new TopicExample();
		Criteria criteria = example.createCriteria();
		criteria.andProblemEqualTo(problem);
		long count = topicMapper.countByExample(example);
		return count==0;
	}
	public static Integer retrieve(String problem) {
		// TODO Auto-generated method stub
	Topic topic= topicMapper.selectByProblem(problem);
	return topic.getTopicid();
	}
	public List<Topic> getAll() {
		// TODO Auto-generated method stub
		return topicMapper.selectByExampleWithOptions(null);
	}
}
